﻿Public Class FrmEmail

    Private Sub FrmEmail_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        cargarConfigEmail()
    End Sub

    Private Sub btGuardar_Click(sender As System.Object, e As System.EventArgs) Handles btGuardar.Click
        If validarCampos() Then
            guardar()
        End If
    End Sub

    Private Sub btSalir_Click(sender As System.Object, e As System.EventArgs) Handles btSalir.Click
        Me.Close()
    End Sub

    Private Sub guardar()
        Dim result As GBDZafiro.Resultado = GBDZafiro.Configuracion.Actualizar(tbDominio.Text, tbEmail.Text, _
                                                                               tbClave.Text, tbPuerto.Text)
        If result.ExisteError Then
            msnBox.msnExclamacion(result.Mensaje)

        Else
            msnBox.msnInformacion("Guardado Con Exito")

        End If
    End Sub

    Private Function validarCampos() As Boolean
        If tbClave.TextLength < 1 Or tbDominio.TextLength < 1 Or _
            tbEmail.TextLength < 1 Or tbPuerto.TextLength < 1 Then
            msnBox.msnExclamacion("Complete Todos los campos!!!")
            Return False

        Else
            Return True

        End If
    End Function

    Private Sub cargarConfigEmail()
        Dim dtConfigEmail As DataTable = GBDZafiro.Configuracion.ConsConfigEmail()
        For Each rConfigEmail As DataRow In dtConfigEmail.Rows
            If rConfigEmail("CODIGO") = "MAIL_SALIDA_SMTP" Then
                tbDominio.Text = rConfigEmail("VALOR")

            ElseIf rConfigEmail("CODIGO") = "MAIL_SALIDA_EMAIL" Then
                tbEmail.Text = rConfigEmail("VALOR")

            ElseIf rConfigEmail("CODIGO") = "MAIL_SALIDA_CLAVE" Then
                tbClave.Text = rConfigEmail("VALOR")

            ElseIf rConfigEmail("CODIGO") = "MAIL_SALIDA_PUERTO" Then
                tbPuerto.Text = rConfigEmail("VALOR")

            End If
        Next
    End Sub

End Class